/*
 *  Copyright 2004 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.webapp.form.core;

import com.blandware.atleap.webapp.form.BaseForm;
import org.apache.struts.action.ActionMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

/**
 * <p>This form bean represents all global properties at once because of batch update</p>
 * <p><a href="GlobalPropertyForm.java.html"><i>View Source</i></a></p>
 * <p/>
 *
 * @author Sergey Zubtsovskiy <a href="mailto:sergey.zubtsovskiy@blandware.com">&lt;sergey.zubtsovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.4 $ $Date: 2006/08/03 10:08:05 $
 * @struts.form name="globalPropertyForm"
 */
public class GlobalPropertyForm extends BaseForm implements java.io.Serializable {

	/**
	 * List of mappings <code>name -&gt; value</code>
	 */
	protected SortedMap propertyMap = new TreeMap();

	/**
	 * List of mappings <code>id -&gt; version</code>
	 */
	protected SortedMap versionMap = new TreeMap();

	/**
	 * Default empty constructor.
	 */
	public GlobalPropertyForm() {
	}

	/**
	 * Returns map of properties
	 *
	 * @return map of properties
	 */
	public Map getPropertyMap() {
		return propertyMap;
	}

	/**
	 * Sets properties
	 *
	 * @param propertyMap map of properties to set
	 */
	public void setPropertyMap(SortedMap propertyMap) {
		this.propertyMap = propertyMap;
	}

	/**
	 * Returns value of property with specified name
	 *
	 * @param name Name of property
	 * @return Property value
	 */
	public Object getProperty(String name) {
		return propertyMap.get(name);
	}

	/**
	 * Sets value for property with specified name
	 *
	 * @param name  Name of property
	 * @param value Value of property
	 */
	public void setProperty(String name, Object value) {
		propertyMap.put(name, value);
	}

	/**
	 * Returns map of versions
	 *
	 * @return map of versions
	 */
	public Map getVersionMap() {
		return versionMap;
	}

	/**
	 * Sets map of versions
	 *
	 * @param versionMap Map to set
	 */
	public void setVersionMap(SortedMap versionMap) {
		this.versionMap = versionMap;
	}

	/**
	 * Returns version of global property by specified key
	 *
	 * @param key Key to return version for
	 * @return version
	 */
	public Object getVersion(String key) {
		return versionMap.get(key);
	}

	/**
	 * Sets version for specified key
	 *
	 * @param key     Key to set version for
	 * @param version Version to set
	 */
	public void setVersion(String key, Object version) {
		versionMap.put(key, version);
	}

	/**
	 * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
	 */
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		this.propertyMap = new TreeMap();
		this.versionMap = new TreeMap();
	}

}
